package com.wen.utils;

import com.wen.moudle.Account;

import java.util.List;
import java.util.Scanner;

public class ConsoleUtils {
    private ConsoleUtils(){}
    private static final Scanner  in = new Scanner(System.in);

    // 获取y或者n
    public static boolean yesOrNo(){
        while (true){
            String line = in.nextLine();
            if (line.length() != 1 || (line.charAt(0) != 'y' && line.charAt(0) != 'n')) {
                System.out.println("请输入[y/n]");
                continue;
            }
            return line.charAt(0) == 'y';
        }
    }

    // 输入一个数字
    public static int inputNumber(){
        while (true){
            String line = in.nextLine();
            if (line.length() == 0 || !line.matches("\\d+")) {
                System.out.println("请输入数字！");
                continue;
            }
            return Integer.parseInt(line);
        }
    }

    // 输入一个数字 []
    public static int inputNumber(int minValue, int maxValue){
        while (true){
            int v = inputNumber();
            if (v < minValue || v > maxValue){
                System.out.println("请输入合理数字！");
                continue;
            }
            return v;
        }
    }

    public static void printList(List<String> list){
        for (int i = 0; i < list.size(); i++) {
            System.out.println(String.format("| %d、%s", i,list.get(i)));
        }
    }

    public static String inputLine(){
        while (true){
            String line = in.nextLine();
            if (line.length() == 0){
                System.out.println("输入不能为空");
                continue;
            }
            return line;
        }
    }
    // 任意键
    public static void enter(){
        in.nextLine();
    }

    public static void printSeparator(){
        System.out.println("==================");
    }

    public static void printName(Account account){
        System.out.print(String.format("【Lv.%d %s】>>>", account.level, account.name));
    }
}
